/**
 * 过滤顶级id，实现半选中
 * @param menuData{Array} tree树list
 * @param userMenu{Array} 用户的权限list
 * @returns {*[]}
 */
function handleMenuData(menuData, userMenu) {
  const result = []
  menuData.forEach(item => {
    if (userMenu.includes(item.permissionId)) {
      if (item.children) {
        const subMenu = handleMenuData(item.children, userMenu)
        if (subMenu.length === item.children.length) {
          result.push(item.permissionId)
        } else if (subMenu.length > 0) {
          result.push(...subMenu)
        }
      } else {
        result.push(item.permissionId)
      }
    }
  })
  return result
}

export default handleMenuData
